<?php

namespace app\admin\controller\yalimedia;

use addons\yalimedia\library\AlibabaCloundHelper;

use addons\yalimedia\library\QRcode;
use app\admin\model\yalimedia\course\Content;
use app\common\controller\Backend;
use fast\Tree;
use think\Request;

/**
 * 课程
 *
 * @icon fa fa-circle-o
 */
class Order extends Backend
{

    protected $noNeedRight = [];
    /**
     * Order模型对象
     * @var \app\admin\model\yalimedia\Order
     */
    protected $model = null;

    public function _initialize()
    {
        parent::_initialize();
        $this->model = new \app\admin\model\yalimedia\Order();

    }

    /**
     * 查看
     */
    public function index()
    {
        //设置过滤方法
        $this->request->filter(['strip_tags', 'trim']);
        if ($this->request->isAjax()) {
            //如果发送的来源是Selectpage，则转发到Selectpage
            if ($this->request->request('keyField')) {
                return $this->selectpage();
            }
            list($where, $sort, $order, $offset, $limit) = $this->buildparams();

            $list = $this->model
                ->where($where)
                ->where(['type'=>1])
                //->where(['status'=>2])
                ->order($sort, $order)
                ->paginate($limit);

            foreach ($list->items() as &$v){
                $courseModel = new \app\admin\model\yalimedia\Course();
                $course = $courseModel->where(['id'=>$v['item_id']])->find();

                $v['course_name'] = empty($course)?'':$course['title'];
            }
            $result = array("total" => $list->total(), "rows" => $list->items());

            return json($result);
        }
        return $this->view->fetch();
    }



}
